<?php
/**
 * Created by PhpStorm.
 * User: XZR
 * Date: 2018/8/6
 * Time: 15:14
 */

namespace Admin\Model;



use Think\Model;

class MedicalCommentModel extends Model
{
    protected $tablePrefix = "";
    protected $tableName = 'tb_md_medical_comment';


    /* 自动验证规则 */
    protected $_validate = array(

        array('name', 'require', '评论人必须', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
        array('hospital','require','医院必须',self::MUST_VALIDATE,'regex',self::MODEL_BOTH),
        array('comment', 'require', '评论必须', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
        array('comment_date', 'require', '评论时间必须', self::MUST_VALIDATE, 'regex', self::MODEL_BOTH),
    );
    private static $instance;

    public static function singleton()
    {
        self::$instance === null and self::$instance = new self();
        return self::$instance;
    }

    public function getList($record_id){
        $where['record_id']=$record_id;
        $where['is_show']=1;
        $where['parent_id']=0;
        $res = $this->where($where)->select();
        $res || [];
        return $res;
    }

    public function top($id){
        $data['is_top']   =   '1';
        $id    = is_array($id) ? implode(',',$id) : $id;
        $where['id']=array('IN',$id);
        return $this->where($where)->save($data);
    }
    public function low($id){
        $data['is_top']   =   '0';
        $id    = is_array($id) ? implode(',',$id) : $id;
        $where['id']=array('IN',$id);
        return $this->where($where)->save($data);
    }

    //删除经纪人
    public function del($map,$record_id){
        RecordModel::singleton()->descNewCommentCount($record_id);
        return $this->where($map)->save(['is_show'=>0]);

    }
}